package com.editso.haier.result;

import com.editso.haier.entity.Assets;
import com.editso.haier.entity.Customer;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.shiro.util.Assert;

import java.util.*;

@Data
@AllArgsConstructor
public class DetailsCustomer {
    private Integer id;
    private String name;
    private Set<Assets> assets;
    private Date date;


    public static DetailsCustomer from(Customer customer, boolean details){
        return new DetailsCustomer(
                customer.getId(),
                customer.getName(),
                details ? customer.getAssets() : null,
                customer.getCreateDate()
        );
    }

    public static Set<DetailsCustomer> from(Iterable<Customer> customers, boolean details){
        Set<DetailsCustomer> set = new HashSet<>();
        for (Customer customer : customers) {
           set.add(from(customer, details));
        }
        return set;
    }

}
